package com.powernobug.service.impl;

import com.powernobug.bean.model.MarketCoupon;
import com.powernobug.bean.model.MarketCouponExample;
import com.powernobug.bean.vo.template.CouponsTempForHomeIndex;
import com.powernobug.mapper.MarketCouponMapper;
import com.powernobug.annotation.PrintThreadLog;
import com.powernobug.service.MarketCouponService;
import com.powernobug.util.TransferModelDataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;

/**
 * @Author: 肖云戈
 * @CreateTime: 2024-08-30
 * @Description:
 */
@Service
public class MarketCouponServiceImpl implements MarketCouponService {

    @Autowired
    MarketCouponMapper marketCouponMapper;

    @Override
    @Async("globalThreadPool")
    @PrintThreadLog
    public Future<List<CouponsTempForHomeIndex>> getCoupons() {
        MarketCouponExample example = new MarketCouponExample();
        example.createCriteria().andDeletedEqualTo(false);
        example.setOrderByClause("discount desc");

        List<MarketCoupon> originData = marketCouponMapper.selectByExample(example);
        Class<?> resultType = CouponsTempForHomeIndex.class;
        List<CouponsTempForHomeIndex> resultData = (List<CouponsTempForHomeIndex>) TransferModelDataUtil.transferFatherToSon(resultType, originData);
        return new AsyncResult<>(resultData);
    }

}
